<?php

class Evento_model extends CI_Model {

    private $tabla = "eventos";

    public function __construct() {
        parent::__construct();
    }

    /** Metodo Utilitario* */
    function _required($required, $data) {
        foreach ($required as $field)
            if (!isset($data[$field]))
                return false;

        return true;
    }

    function save($id, $start, $end, $title, $body, $tipoInstalacion) {
        $data = array(
            'id' => $id,
            'start' => $start,
            'end' => $end,
            'title' => $title,
            'body' => $body,
            'tipoInstalacion'=> $tipoInstalacion
        );
        $this->db->insert($this->tabla, $data);
        return $this->db->insert_id();
    }

    
  function get_count(){
     $query = $this->db->query('SELECT max(id ) AS id FROM eventos');
     $res=$query->result();
     return $res;
   
  }  
      
  
  
  function get_events($tipoInstalacion){     
 
      $query = $this->db->query('SELECT * FROM eventos WHERE eventos.tipoInstalacion ='.$tipoInstalacion);
       return $query->result();
       
  }
  
  
  function delete($id){
        $query = $this->db->query('DELETE FROM eventos WHERE id='. $id);
        if ($error = $this->db->_error_number())
            ;
      //  echo $error;
      
  }
  
   
  function move ($id, $start, $end){
        $query = $this->db->query("UPDATE eventos SET start = '".$start."',
		  end = '".$end."' WHERE eventos.id =".$id);
      
  }
  
  function update($id, $start, $title, $end, $body){
     $query = $this->db->query("UPDATE eventos SET title = '".$title."', body = '".$body."',start = '".$start."',
		  end = '".$end."' WHERE eventos.id =".$id);

     } 
 
}

?>